using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime;
using System.Security.Permissions;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.ConnectionPool;
using OracleInternal.Network;
using OracleInternal.ServiceObjects;

namespace OracleInternal.Common
{
	internal class ProviderConfig : ConfigBaseClass
	{
		internal static class MaxStatementCacheSize
		{
			private const int DEFAULT_MAX_STATEMENT_CACHE_SIZE = 200;

			internal static int Value
			{
				get
				{
					if (ConfigBaseClass.m_MaxStatementCacheSize != -1)
					{
						return ConfigBaseClass.m_MaxStatementCacheSize;
					}
					return 200;
				}
			}

			internal static bool IsUserDefined => ConfigBaseClass.m_MaxStatementCacheSize != -1;
		}

		private const string ORA_DEBUG_JDWP = "ORA_DEBUG_JDWP";

		private const string TNS_ADMIN = "TNS_ADMIN";

		private const string LDAP_ADMIN = "LDAP_ADMIN";

		private const string ORACLE_HOME = "ORACLE_HOME";

		private static readonly string NETWORK_ADMIN;

		private static readonly string LDAP_ADMIN_DIR;

		internal const string LDAPORA = "ldap.ora";

		internal const string TNSNAMESORA = "tnsnames.ora";

		internal const string SQLNETORA = "sqlnet.ora";

		internal static bool m_bTraceLevelPublic;

		internal static bool m_bTraceLevelPrivate;

		internal static bool m_bTraceLevelNetwork;

		internal static bool m_bTraceLevelConfig;

		internal static bool m_bTraceLevelSecure;

		internal static bool m_bTraceLevelPrivate_NoTrace;

		private static string s_appConfigFilePath;

		internal static Hashtable ConfigDataSourcesMap => ConfigBaseClass.m_configDataSourcesMap;

		private static string OracleHome
		{
			get
			{
				if (!ConfigBaseClass.m_OracleHomeSet)
				{
					ConfigBaseClass.m_OracleHome = Environment.GetEnvironmentVariable("ORACLE_HOME");
					if (!string.IsNullOrEmpty(ConfigBaseClass.m_OracleHome))
					{
						ConfigBaseClass.m_OracleHome.Trim();
					}
					else
					{
						ConfigBaseClass.m_OracleHome = string.Empty;
					}
					ConfigBaseClass.m_OracleHomeSet = true;
				}
				return ConfigBaseClass.m_OracleHome;
			}
		}

		internal static void OnAppConfigFileChanged()
		{
			string traceFilePath = ConfigBaseClass.m_traceFileLocation;
			int traceLevel = ConfigBaseClass.m_TraceLevel;
			bool traceOption = ((ConfigBaseClass.m_TraceOption == 1) ? true : false);
			long traceFileMaxSize = ConfigBaseClass.m_TraceFileMaxSize;
			try
			{
				XElement xElement = XElement.Load(s_appConfigFilePath).Element("oracle.manageddataaccess.client");
				Dictionary<string, XElement> dictionary = new Dictionary<string, XElement>();
				foreach (XElement item in xElement.Elements("version"))
				{
					if (dictionary.ContainsKey(item.Attribute("number").Value))
					{
						dictionary[item.Attribute("number").Value] = item;
					}
					else
					{
						dictionary.Add(item.Attribute("number").Value, item);
					}
				}
				if (dictionary.Any())
				{
					XElement value = null;
					if (dictionary.TryGetValue("*", out value) && value != null)
					{
						ReadTraceSettingsFromConfigVersionNode(value, ref traceFilePath, ref traceLevel, ref traceOption, ref traceFileMaxSize);
					}
					if (dictionary.TryGetValue(ConfigBaseClass.m_assemblyVersion.ToString(), out value) && value != null)
					{
						ReadTraceSettingsFromConfigVersionNode(value, ref traceFilePath, ref traceLevel, ref traceOption, ref traceFileMaxSize);
					}
					bool flag = traceFilePath != ConfigBaseClass.m_traceFileLocation;
					if (traceFileMaxSize != ConfigBaseClass.m_TraceFileMaxSize || flag || traceLevel != ConfigBaseClass.m_TraceLevel || (traceOption ? 1 : 0) != ((ConfigBaseClass.m_TraceOption == 1) ? 1 : 0))
					{
						ConfigBaseClass.m_TraceLevel = traceLevel;
						ConfigBaseClass.m_TraceOption = (traceOption ? 1 : 0);
						ConfigBaseClass.m_traceFileLocation = traceFilePath;
						ConfigBaseClass.m_TraceFileMaxSize = traceFileMaxSize;
						Trace.ReInit(flag);
					}
				}
			}
			catch
			{
			}
		}

		private static void ReadTraceSettingsFromConfigVersionNode(XElement versionNode, ref string traceFilePath, ref int traceLevel, ref bool traceOption, ref long traceFileMaxSize)
		{
			XElement xElement = versionNode.Element("settings");
			if (xElement == null)
			{
				return;
			}
			int result = 0;
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (XElement item in xElement.Elements())
			{
				if (dictionary.ContainsKey(item.Attribute("name").Value))
				{
					dictionary[item.Attribute("name").Value] = item.Attribute("value").Value;
				}
				else
				{
					dictionary.Add(item.Attribute("name").Value, item.Attribute("value").Value);
				}
			}
			string value = null;
			if (dictionary.TryGetValue("TraceLevel", out value) && int.TryParse(value, out result))
			{
				traceLevel = result;
			}
			string value2 = null;
			if (dictionary.TryGetValue("TraceOption", out value2) && int.TryParse(value2, out result))
			{
				traceOption = ((result != 0) ? true : false);
			}
			string value3 = null;
			if (dictionary.TryGetValue("TraceFileLocation", out value3))
			{
				traceFilePath = value3;
			}
			result = 0;
			string value4 = null;
			if (dictionary.TryGetValue("TraceFileMaxSize", out value4) && int.TryParse(value4, out result))
			{
				result = ((result > 0) ? (result * 1024 * 1024) : 104857600);
				traceFileMaxSize = result;
			}
		}

		static ProviderConfig()
		{
			NETWORK_ADMIN = Path.Combine("network", "admin");
			LDAP_ADMIN_DIR = Path.Combine("ldap", "admin");
			m_bTraceLevelPrivate_NoTrace = false;
			s_appConfigFilePath = null;
			ConfigBaseClass.GetInstance(bIsManaged: true);
		}

		private static Version GetExecutingAssemblyVersion()
		{
			return Assembly.GetExecutingAssembly().GetName().Version;
		}

		internal static void ReParseDataSourceSection()
		{
			ConfigBaseClass.m_ParseMode = ParseMode.ReParseTnsNames;
			CustomConfigFileReader customConfigFileReader = ConfigBaseClass.GetInstance(bIsManaged: true) as CustomConfigFileReader;
			try
			{
				if (ConfigBaseClass.m_configDataSourcesMap != null && ConfigBaseClass.m_configDataSourcesMap.Count > 0)
				{
					List<string> dataSources = OracleConnectionDispenser<OraclePoolManager, OraclePool, OracleConnectionImpl>.GetDataSources();
					string[] array = new string[ConfigBaseClass.m_configDataSourcesMap.Count];
					ConfigBaseClass.m_configDataSourcesMap.Keys.CopyTo(array, 0);
					string[] array2 = array;
					foreach (string text in array2)
					{
						if (!dataSources.Contains(text))
						{
							ConfigBaseClass.m_configDataSourcesMap.Remove(text);
						}
					}
				}
				for (int j = 0; j < ConfigBaseClass.m_versionSpecificNodesList.Count; j++)
				{
					customConfigFileReader.ParseSubSection((XmlNode)ConfigBaseClass.m_versionSpecificNodesList[j], ref customConfigFileReader.s_storedProcInformation, new ArrayList
					{
						"dataSources"
					});
				}
			}
			catch
			{
				throw;
			}
			finally
			{
				ConfigBaseClass.m_versionSpecificNodesList.Clear();
				ConfigBaseClass.m_ParseMode = ParseMode.None;
			}
		}

		internal static void RefreshDataSources()
		{
			lock (OracleConnectionDispenser<OraclePoolManager, OraclePool, OracleConnectionImpl>.m_syncObjForGetDataSources)
			{
				AddressResolution.RefreshNamingAdapters();
			}
		}

		internal static void NewOraFileParams(OraFiles file, string filePath, Hashtable theParams, bool ObCfg = false)
		{
			OracleTraceTag traceTag = ((file == OraFiles.TnsNames) ? OracleTraceTag.Tnsnames : OracleTraceTag.Sqlnet);
			bool flag = false;
			List<string> list = null;
			if (file == OraFiles.TnsNames && ConfigBaseClass.m_ParseMode == ParseMode.ReParseTnsNames && theParams != null && theParams.Count > 0)
			{
				flag = true;
				list = OracleConnectionDispenser<OraclePoolManager, OraclePool, OracleConnectionImpl>.GetDataSources();
				string[] array = new string[theParams.Count];
				theParams.Keys.CopyTo(array, 0);
				string[] array2 = array;
				foreach (string text in array2)
				{
					if (!list.Contains(text))
					{
						theParams.Remove(text);
					}
				}
			}
			if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
			{
				return;
			}
			CustomConfigFileReader customConfigFileReader = ConfigBaseClass.GetInstance(bIsManaged: true) as CustomConfigFileReader;
			Hashtable hashtable = file switch
			{
				OraFiles.Ldap => ConfigBaseClass.m_LDAPCfParamFrAppConfig, 
				OraFiles.SqlNet => ConfigBaseClass.m_configParamFrAppConfig, 
				_ => null, 
			};
			Hashtable oracleConfigParameters = ConfigBaseClass.m_oracleConfigParameters;
			using StreamReader strmRdr = new StreamReader(filePath);
			string leftover;
			string[] name = customConfigFileReader.GetName(strmRdr, out leftover);
			while (name != null && name.Length != 0)
			{
				string value = customConfigFileReader.GetValue(strmRdr, leftover);
				if (!string.IsNullOrEmpty(value))
				{
					string[] array2 = name;
					foreach (string text2 in array2)
					{
						if ((hashtable != null && hashtable[text2] != null && (bool)hashtable[text2]) || oracleConfigParameters.ContainsKey(text2))
						{
							continue;
						}
						if (ConfigBaseClass.m_TraceLevel > 0)
						{
							Trace.Write(OracleTraceLevel.Config, traceTag, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.NewOraFileParams, text2 + " : " + value);
						}
						if (!flag || !list.Contains(text2))
						{
							theParams[text2] = value;
							if (file == OraFiles.SqlNet && !ObCfg)
							{
								ConfigBaseClass.m_configParamFrSqlnetora[text2] = true;
							}
						}
					}
				}
				name = customConfigFileReader.GetName(strmRdr, out leftover);
			}
		}

		internal static string getFilePath(OraFiles file, string dir, string fileName)
		{
			dir = ConfigBaseClass.GetResolvedFileLocation(dir);
			if (file == OraFiles.TnsNames)
			{
				ConfigBaseClass.m_TNSConfigPath.Add(Path.Combine(dir, "tnsnames.ora"));
			}
			return FindFile(dir, fileName);
		}

		[SecurityPermission(SecurityAction.Assert, Unrestricted = true)]
		internal static string NewOraFileLoc(OraFiles file)
		{
			string empty = string.Empty;
			string empty2 = string.Empty;
			if (file == OraFiles.TnsNames)
			{
				ConfigBaseClass.m_TNSConfigPath.Clear();
			}
			empty2 = file switch
			{
				OraFiles.SqlNet => "sqlnet.ora", 
				OraFiles.TnsNames => "tnsnames.ora", 
				_ => "ldap.ora", 
			};
			if (!string.IsNullOrEmpty(ConfigBaseClass.m_TnsAdminLocation))
			{
				empty = getFilePath(file, ConfigBaseClass.m_TnsAdminLocation, empty2);
				if (empty.Length > 0)
				{
					return empty;
				}
			}
			if (file == OraFiles.Ldap && !string.IsNullOrEmpty(ConfigBaseClass.m_LdapAdminLocation))
			{
				empty = getFilePath(file, ConfigBaseClass.m_LdapAdminLocation, empty2);
				if (empty.Length > 0)
				{
					return empty;
				}
			}
			empty = getFilePath(file, ".", empty2);
			if (empty.Length > 0)
			{
				return empty;
			}
			empty = getFilePath(file, Directory.GetCurrentDirectory(), empty2);
			if (empty.Length > 0)
			{
				return empty;
			}
			if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TNS_ADMIN")))
			{
				empty = getFilePath(file, Environment.GetEnvironmentVariable("TNS_ADMIN"), empty2);
				if (empty.Length > 0)
				{
					return empty;
				}
			}
			if (file == OraFiles.Ldap && !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("LDAP_ADMIN")))
			{
				empty = getFilePath(file, Environment.GetEnvironmentVariable("LDAP_ADMIN"), empty2);
				if (empty.Length > 0)
				{
					return empty;
				}
			}
			if (!string.IsNullOrWhiteSpace(OracleHome))
			{
				empty = getFilePath(file, Path.Combine(OracleHome, NETWORK_ADMIN), empty2);
				if (empty.Length > 0)
				{
					return empty;
				}
				if (file == OraFiles.Ldap)
				{
					empty = FindFile(Path.Combine(OracleHome, LDAP_ADMIN_DIR), empty2);
				}
			}
			return empty;
		}

		internal static string FindFile(string filePath, string fileName)
		{
			string text = string.Empty;
			if (!string.IsNullOrEmpty(filePath))
			{
				filePath.Trim();
				text = Path.Combine(filePath, fileName);
				if (!File.Exists(text))
				{
					if (m_bTraceLevelPrivate)
					{
						Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Config, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.FindFile, $"({fileName}) Searching for '{text}' : not found");
					}
					text = string.Empty;
				}
				else if (m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Config, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.FindFile, $"({fileName}) Searching for '{text}' : found!");
				}
			}
			return text;
		}

		internal void ParseConfigParamsForODT(XmlNode baseNode, ref Hashtable storedProcInformation)
		{
			ArrayList filterNodes = new ArrayList
			{
				"edmMappings",
				"implicitRefCursor"
			};
			ArrayList arrayList = new ArrayList();
			CustomConfigFileReader customConfigFileReader = ConfigBaseClass.GetInstance(bIsManaged: true) as CustomConfigFileReader;
			customConfigFileReader.ParseClientXmlNode(baseNode, ref storedProcInformation, ref arrayList, filterNodes);
			for (int i = 0; i < arrayList.Count; i++)
			{
				customConfigFileReader.ParseSubSection((XmlNode)arrayList[i], ref storedProcInformation, filterNodes);
			}
		}

		internal static void ValidateBaseDocument(XmlDocument doc)
		{
			doc.Schemas.Add(null, new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Oracle.ManagedDataAccess.src.Common.Resources.Oracle.DataAccess.Common.Configuration.Section.xsd")));
			doc.Schemas.Add(null, new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Oracle.ManagedDataAccess.src.Common.Resources.Oracle.ManagedDataAccess.Client.Configuration.Section.xsd")));
			ValidationEventHandler validationEventHandler = ValidationCallBack;
			doc.Validate(validationEventHandler);
		}

		private static void ValidationCallBack(object sender, ValidationEventArgs args)
		{
			if (args.Severity == XmlSeverityType.Warning)
			{
				if (m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.ValidationCallBack, "Warning: Matching schema not found.  No validation occurred." + args.Message);
				}
				return;
			}
			throw new ConfigurationErrorsException(args.Message);
		}

		internal static string GetPropertyFromONSConfig(string ONSConfigFile, string onsConfigProperty)
		{
			return (ConfigBaseClass.GetInstance(bIsManaged: true) as CustomConfigFileReader).GetPropertyFromONSConfig(ONSConfigFile, onsConfigProperty);
		}

		private static void AddInfoForRefCursor(string storedProcKey, XmlNode refCursorNode, ref Hashtable storedProcInformation)
		{
			if (refCursorNode.Attributes != null)
			{
				bool isInfoBasedOnName = false;
				RefCursorInfo refCursorInfo = new RefCursorInfo();
				XmlAttribute xmlAttribute = refCursorNode.Attributes["name"];
				XmlAttribute xmlAttribute2 = refCursorNode.Attributes["position"];
				string s;
				string name;
				if (xmlAttribute2 != null && !string.IsNullOrWhiteSpace(s = xmlAttribute2.Value.Trim()))
				{
					refCursorInfo.position = int.Parse(s);
					isInfoBasedOnName = false;
				}
				else if (xmlAttribute != null && !string.IsNullOrWhiteSpace(name = xmlAttribute.Value.Trim()))
				{
					refCursorInfo.name = name;
					isInfoBasedOnName = true;
					refCursorInfo.position = -1;
				}
				else
				{
					string messageForTrace = "Neither RefCursor name nor position is present in " + storedProcKey;
					string messageForException = storedProcKey + "  refCursor";
					ThrowExceptionForRefCursor(messageForTrace, messageForException);
				}
				foreach (XmlNode childNode in refCursorNode.ChildNodes)
				{
					string name2 = childNode.Name;
					if (!(name2 == "bindInfo"))
					{
						if (name2 == "metadata")
						{
							AddMetadataForRefCursor(storedProcKey, childNode, ref refCursorInfo, isInfoBasedOnName, ref storedProcInformation);
						}
					}
					else
					{
						AddBindInfoForRefCursor(storedProcKey, childNode, ref refCursorInfo, isInfoBasedOnName, ref storedProcInformation);
					}
				}
			}
			else
			{
				string messageForTrace2 = "Neither RefCursor name nor position is present in stored procedure " + storedProcKey;
				string messageForException2 = storedProcKey + "  refCursor";
				ThrowExceptionForRefCursor(messageForTrace2, messageForException2);
			}
		}

		private static void AddBindInfoForRefCursor(string storedProcKey, XmlNode bindInfoNode, ref RefCursorInfo refCursorInfo, bool isInfoBasedOnName, ref Hashtable storedProcInformation)
		{
			string value = bindInfoNode.Attributes["mode"].Value;
			refCursorInfo.mode = (ParameterDirection)Enum.Parse(typeof(ParameterDirection), value, ignoreCase: true);
			StoredProcedureInfo storedProcedureInfo = (StoredProcedureInfo)storedProcInformation[storedProcKey];
			int num = 0;
			foreach (RefCursorInfo refCursor in storedProcedureInfo.m_refCursors)
			{
				if (isInfoBasedOnName)
				{
					if (refCursor.name.Length > 0 && refCursor.name.Equals(refCursorInfo.name))
					{
						storedProcedureInfo.m_refCursors.RemoveAt(num);
						break;
					}
				}
				else if (refCursor.position >= refCursorInfo.position)
				{
					if (refCursor.position == refCursorInfo.position)
					{
						storedProcedureInfo.m_refCursors.RemoveAt(num);
					}
					storedProcedureInfo.m_refCursors.Insert(num, refCursorInfo);
					return;
				}
				num++;
			}
			storedProcedureInfo.m_refCursors.Add(refCursorInfo);
		}

		private static void AddMetadataForRefCursor(string storedProcKey, XmlNode metadataNode, ref RefCursorInfo refCursorInfo, bool isInfoBasedOnName, ref Hashtable storedProcInformation)
		{
			int num = int.Parse(metadataNode.Attributes["columnOrdinal"].Value.Trim());
			_ = (StoredProcedureInfo)storedProcInformation[storedProcKey];
			DataRow dataRow = refCursorInfo.columnInfo.NewRow();
			CustomConfigFileReader customConfigFileReader = ConfigBaseClass.GetInstance(bIsManaged: true) as CustomConfigFileReader;
			foreach (XmlAttribute attribute in metadataNode.Attributes)
			{
				string text = attribute.Value.Trim();
				switch (attribute.Name.ToUpperInvariant())
				{
				case "COLUMNORDINAL":
					dataRow["ColumnOrdinal"] = num;
					break;
				case "COLUMNNAME":
					dataRow["ColumnName"] = customConfigFileReader.GetAttrValueInProperCase(text);
					break;
				case "COLUMNSIZE":
					dataRow["ColumnSize"] = int.Parse(text);
					break;
				case "NUMERICPRECISION":
					dataRow["NumericPrecision"] = int.Parse(text);
					break;
				case "NUMERICSCALE":
					dataRow["NumericScale"] = int.Parse(text);
					break;
				case "ISUNIQUE":
					dataRow["IsUnique"] = bool.Parse(text);
					break;
				case "ISKEY":
					dataRow["IsKey"] = bool.Parse(text);
					if ((bool)dataRow["IsKey"])
					{
						refCursorInfo.isPrimaryKeyPresent = true;
					}
					break;
				case "ISROWID":
					dataRow["IsRowID"] = bool.Parse(text);
					break;
				case "BASECOLUMNNAME":
					dataRow["BaseColumnName"] = customConfigFileReader.GetAttrValueInProperCase(text);
					break;
				case "BASESCHEMANAME":
					dataRow["BaseSchemaName"] = customConfigFileReader.GetAttrValueInProperCase(text);
					break;
				case "BASETABLENAME":
					dataRow["BaseTableName"] = customConfigFileReader.GetAttrValueInProperCase(text);
					break;
				case "DATATYPE":
					dataRow["DataType"] = Type.GetType(text);
					break;
				case "PROVIDERTYPE":
					dataRow["ProviderType"] = (OracleDbType)Enum.Parse(typeof(OracleDbType), text.Split('.')[text.Split('.').Length - 1], ignoreCase: true);
					break;
				case "ALLOWDBNULL":
					dataRow["AllowDBNull"] = bool.Parse(text);
					break;
				case "ISALIASED":
					dataRow["IsAliased"] = bool.Parse(text);
					break;
				case "ISBYTESEMANTIC":
					dataRow["IsByteSemantic"] = bool.Parse(text);
					break;
				case "ISEXPRESSION":
					dataRow["IsExpression"] = bool.Parse(text);
					break;
				case "ISHIDDEN":
					dataRow["IsHidden"] = bool.Parse(text);
					break;
				case "ISREADONLY":
					dataRow["IsReadOnly"] = bool.Parse(text);
					break;
				case "ISLONG":
					dataRow["IsLong"] = bool.Parse(text);
					break;
				case "UDTTYPENAME":
					dataRow["UdtTypeName"] = customConfigFileReader.GetAttrValueInProperCase(text);
					break;
				case "NATIVEDATATYPE":
					dataRow["NativeDataType"] = customConfigFileReader.GetAttrValueInProperCase(text);
					break;
				case "PROVIDERDBTYPE":
					dataRow["ProviderDBType"] = (DbType)Enum.Parse(typeof(DbType), text.Split('.')[text.Split('.').Length - 1], ignoreCase: true);
					break;
				case "OBJECTNAME":
					dataRow["ObjectName"] = customConfigFileReader.GetAttrValueInProperCase(text);
					break;
				}
			}
			if (refCursorInfo.columnInfo.Rows.Count > num)
			{
				refCursorInfo.columnInfo.Rows.InsertAt(dataRow, num);
			}
			else
			{
				refCursorInfo.columnInfo.Rows.Add(dataRow);
			}
			refCursorInfo.columnInfo.AcceptChanges();
		}

		private static void ThrowExceptionForRefCursor(string messageForTrace, string messageForException)
		{
			if (m_bTraceLevelConfig)
			{
				Trace.Write(OracleTraceLevel.Config, OracleTraceTag.REFCursor, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.ThrowExceptionForRefCursor, messageForTrace);
			}
			throw new ConfigurationErrorsException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_INVALID_VALUE, messageForException));
		}

		internal static string GetONSConfiguration(string databaseName)
		{
			if (ConfigBaseClass.m_ONSMapping == null || !ConfigBaseClass.m_ONSMapping.ContainsKey(databaseName.ToLowerInvariant()))
			{
				return string.Empty;
			}
			Dictionary<string, string> dictionary = ConfigBaseClass.m_ONSMapping[databaseName.ToLowerInvariant()];
			StringBuilder stringBuilder = new StringBuilder();
			string text = dictionary["nodeList"];
			if (text != null)
			{
				stringBuilder.AppendFormat("nodes.list={0}", text);
			}
			return stringBuilder.ToString();
		}

		internal static void TraceConfigAndEnvParams()
		{
			Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Environment, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "Machine Name : " + Environment.MachineName);
			Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Environment, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "User Name : " + Environment.UserName);
			Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Environment, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "OS Version : " + Environment.OSVersion);
			Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Environment, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "64-bit OS : " + Environment.Is64BitOperatingSystem);
			Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Environment, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "64-bit Process : " + Environment.Is64BitProcess);
			try
			{
				char[] separator = new char[2]
				{
					'/',
					'\\'
				};
				string[] array = typeof(GCSettings).GetTypeInfo().Assembly.CodeBase!.Split(separator, StringSplitOptions.RemoveEmptyEntries);
				int num = Array.IndexOf(array, "Microsoft.NETCore.App");
				if (num > 0 && num < array.Length - 2)
				{
					Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Environment, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, ".NET Core Runtime Version : " + array[num + 1]);
				}
			}
			catch
			{
			}
			Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Environment, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "Application Directory : " + ConfigBaseClass.s_appDir);
			string str = ConfigBaseClass.m_assemblyVersion.ToString();
			Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Version, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "Oracle Data Provider for .NET Core Driver Version : " + str);
			try
			{
				FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
				Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Version, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "Oracle Data Provider for .NET Core Driver Informational Version : " + versionInfo.ProductVersion);
			}
			catch
			{
				Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Version, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "Informational Version : Unable to retrieve.");
			}
			foreach (string key in ConfigBaseClass.m_configParameters.Keys)
			{
				if (!OracleConfiguration.propertySetByOcfg.ContainsKey(key))
				{
					Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Config, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, key + " : " + ConfigBaseClass.m_configParameters[key]!.ToString());
				}
			}
			if (!OracleConfiguration.propertySetByOcfg.ContainsKey(OracleTraceFuncName.TraceFileLocation.ToString()))
			{
				Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Config, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "Resolved Trace File Location: " + ConfigBaseClass.m_singleTraceFileLocation);
			}
			CustomConfigFileReader customConfigFileReader = ConfigBaseClass.GetInstance(bIsManaged: true) as CustomConfigFileReader;
			if (customConfigFileReader != null)
			{
				TraceImplicitRefCursorParams(ref customConfigFileReader.s_storedProcInformation, isODTCall: false);
			}
			Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Sqlnet, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "FilePath : " + (string.IsNullOrEmpty(ConfigBaseClass.m_sqlnetOraLoc) ? "(null)" : ConfigBaseClass.m_sqlnetOraLoc));
			Trace.Write(OracleTraceLevel.Config, OracleTraceTag.Tnsnames, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceConfigAndEnvParams, "FilePath : " + (string.IsNullOrEmpty(ConfigBaseClass.m_TNSNamesoraloc) ? "(null)" : ConfigBaseClass.m_TNSNamesoraloc));
		}

		private static void TraceImplicitRefCursorParams(ref Hashtable storedProcInformation, bool isODTCall)
		{
			if (storedProcInformation.Keys.Count <= 0)
			{
				return;
			}
			foreach (string key in storedProcInformation.Keys)
			{
				StringBuilder stringBuilder = new StringBuilder();
				foreach (RefCursorInfo refCursor in ((StoredProcedureInfo)storedProcInformation[key]).m_refCursors)
				{
					if (isODTCall)
					{
						stringBuilder.Append("Design-time Implicit Binding Info : [" + key + "]");
					}
					else
					{
						stringBuilder.Append("Run-time Implicit Binding Info : [" + key + "]");
					}
					stringBuilder.Append("[param name/pos=" + ((refCursor.name == string.Empty) ? refCursor.position.ToString() : refCursor.name) + ";");
					stringBuilder.Append("mode=" + refCursor.mode.ToString() + "] Metadata : ");
					string value = stringBuilder.ToString();
					if (refCursor.columnInfo == null)
					{
						stringBuilder.Append("[<none>])");
						Trace.Write(OracleTraceLevel.Config, OracleTraceTag.REFCursor, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceImplicitRefCursorParams, stringBuilder.ToString());
						continue;
					}
					DataTable columnInfo = refCursor.columnInfo;
					for (int i = 0; i < columnInfo.Rows.Count; i++)
					{
						stringBuilder.Append("[");
						for (int j = 0; j < columnInfo.Columns.Count; j++)
						{
							stringBuilder.Append(((j != 0) ? ";" : string.Empty) + columnInfo.Columns[j].ToString() + "=" + columnInfo.Rows[i][j]);
						}
						stringBuilder.Append("])");
						Trace.Write(OracleTraceLevel.Config, OracleTraceTag.REFCursor, OracleTraceClassName.ProviderConfig, OracleTraceFuncName.TraceImplicitRefCursorParams, stringBuilder.ToString());
						stringBuilder.Length = 0;
						stringBuilder.Append(value);
					}
					stringBuilder.Length = 0;
				}
			}
		}

		internal override void setudtmapping(out Hashtable s_mapUdtNameToMappingObj)
		{
			s_mapUdtNameToMappingObj = null;
		}
	}
}
